#ifndef _BUFFER_POOL_H
#define _BUFFER_POOL_H

#include "file_io.h"

/* hide `read_page` and `write page` */

#define CACHE_PAGE 8

typedef struct {
  /* you can modify anything in this struct */
  FileInfo file; /* for simplicity, every file has its own buffer pool */
  Page pages[CACHE_PAGE]; /* allocate CACHE_PAGE pages in buffer pool */
  off_t addrs[CACHE_PAGE]; /* addr for each page */
  size_t age[CACHE_PAGE]; /* age=counter, support LRU replacement policy: get_page=>+1 */
  size_t ref[CACHE_PAGE]; /* to label which page is in use: get_page=>+1, release=>-1 */
} BufferPool;

/* BEGIN: --------------------------------- DO NOT MODIFY! --------------------------------- */

void init_buffer_pool(const char *filename, BufferPool *pool);

void close_buffer_pool(BufferPool *pool);

Page *get_page(BufferPool *pool, off_t addr);

void release(BufferPool *pool, off_t addr);

/* END:   --------------------------------- DO NOT MODIFY! --------------------------------- */

/* void print_buffer_pool(BufferPool *pool); */

/* void validate_buffer_pool(BufferPool *pool); */

#endif  /* _BUFFER_POOL_H */